package com.hrt.datasender.web;

import java.util.ArrayList;
import java.util.List;

import com.btcode.common.MyLog;
import com.btcode.common.PropertiesUnit;
import com.btcode.web.core.server.DefaultServer;
import com.btcode.web.mvc.servlet.ApiPackScanInfo;
import com.btcode.web.safe.service.VerifyService;

public class WebOnly {

    private static final int WEBPORT = 8088;
    public static String controllerPacket = "com.hrt.datasender.web";

    public static void main(String[] args) throws Exception {

        if (args == null || args.length <= 0) {
            throw new Exception("缺少项目根目录配置，webResource的上一级目录");
        }

        String propertiesPath = args[0];
        PropertiesUnit.setPropertiesPath(propertiesPath);

        String logPath = PropertiesUnit.getValue("logPath");
        String webBasePath = PropertiesUnit.getValue("webBasePath");
        String projectName = PropertiesUnit.getValue("webProjectName");

        MyLog.getInstance().setRootPath(logPath);

        String jettyLogPath = logPath + "/jetty.log";

        VerifyService authenticationService = new VerifyService();
        authenticationService.addExceptURL("/login");
        authenticationService.addExceptURL("/webResource/view/sw/login.html");
        authenticationService.addExceptURL("/webResource/js/*");

        List<ApiPackScanInfo> controllerPackets = new ArrayList<>();
        controllerPackets.add(new ApiPackScanInfo("com.hrt.datasender.web", WebMain.class));

        DefaultServer server = new DefaultServer(WEBPORT, jettyLogPath, webBasePath, controllerPackets, projectName);
        server.addUrlMapping("/index.html", "/webResource/view/sw/index.html");
        server.startServer();
    }
}